package com.chencong.online.utils;

/**
 * @program: user-behavior-analysis-online
 * @ClassName BloomFilterUtil
 * @description:布隆过滤器工具类
 * @author: chencong
 * @create: 2021-12-28 16:31
 **/
public class BloomFilterUtil {
    //定义位图的大小（通常需要定义为2的次幂）
    private Integer capacity;

    //定义构造器
    public BloomFilterUtil(Integer capacity) {
        this.capacity = capacity;
    }

    //实现一个简单的hash函数 传id和随机种子seed
    public Long hashCode(String value, Integer seed) {
        Long result = 0L;
        for (int i = 0; i < value.length(); i++) {
            result = result * seed + value.charAt(i);
        }
        return result & (capacity - 1);
    }
}
